﻿using StudentLive.Common;
using StudentLive.DataModel;
using StudentLive.InnerPages;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

namespace StudentLive
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class OldLessonPlansPage : LayoutAwarePage
    {
        public OldLessonPlansPage()
        {
            this.InitializeComponent();
        }

        protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
        {
            // TODO: Assign a collection of bindable groups to this.DefaultViewModel["Groups"]
            // TODO: Create an appropriate data model for your problem domain to replace the sample data
            var allLessonPlanGroups = LiveDataSource.GetAllLessonPlans((String)navigationParameter);
            allLessonPlanGroups = allLessonPlanGroups.OrderBy<CoursePlanItem, string>(course => course.Name);

            this.DefaultViewModel["Groups"] = allLessonPlanGroups;
            //this.DefaultViewModel["FlowDirection"] = Constants.GetFlowDirection();
        }

        private void Unit_Click(object sender, RoutedEventArgs e)
        {
            // Determine what group the Button instance represents
            var group = (sender as FrameworkElement).DataContext;

            // Navigate to the appropriate destination page, configuring the new page
            // by passing required information as a navigation parameter
            this.Frame.Navigate(typeof(LessonDetails), ((CoursePlanItem)group).CoursePlanID);

        }

        private void Lesson_Click(object sender, ItemClickEventArgs e)
        {
            var item = (e.ClickedItem as UnitItem);;
            this.Frame.Navigate(typeof(UnitPage), item.UnitID);
        }
    }
}
